const callbacks = []; // 存储 flushSchedularQueue 函数

let waiting = false; // 防抖原理，防止调用多次标记，开启多个 setTimeout

function flushCallback() {
  // console.log(callbacks)
  callbacks.forEach(cb => cb());
  waiting = false;
}

export function nextTick(callback) {
  callbacks.push(callback);
  if (!waiting) {
    // $nextTick => Promise/mutationObserver/setImmediate/setTimeout
    setTimeout(flushCallback, 0);
    waiting = true;
  }
}